import { v4 as uuidv4 } from "uuid";

export function userTempId() {
  // 先从本地存储拿 userTempId
  let result = localStorage.getItem("userTempId");
  if (result) {
    return result;
  } else {
    // 若拿到userTempId 重新生成
    let newUserTempId = uuidv4();
    // 本地存储
    localStorage.setItem("userTempId", newUserTempId);
    // 返回新生成的 newUserTempId
    return newUserTempId;
  }
}

// 存储token
export function saveToken(token) {
  localStorage.setItem("token", token);
}

// 读取token 一定要有返回值
export function readToken() {
  // console.log(localStorage.getItem("token"));
  return localStorage.getItem("token");
}

// 删除 token
export function deleteToken() {
  localStorage.removeItem("token");
}
